package com.hl.shifangzhiyu.web;

import com.hl.shifangzhiyu.pojo.Consultant1s;
import com.hl.shifangzhiyu.service.Consultant1sService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/consultant1s")
public class Consultant1sController {


    @Autowired
    private Consultant1sService consultant1sService;
@RequestMapping("/listAll")
    public List<Consultant1s> listAll(){
return consultant1sService.listAll();
    }



    @DeleteMapping("/delete/{id}")
    public ResponseEntity<String> deleteConsultant(@PathVariable Long id) {
        boolean isDeleted = consultant1sService.deleteConsultant(id);
        if (isDeleted) {
            return ResponseEntity.ok("删除成功");
        } else {
            return ResponseEntity.badRequest().body("删除失败");
        }
    }

    @PostMapping("/add")
    public ResponseEntity<String> addConsultant(@RequestBody Consultant1s consultant1) {
        boolean isAdded = consultant1sService.addConsultant(consultant1);
        if (isAdded) {
            return ResponseEntity.ok("新增成功");
        } else {
            return ResponseEntity.badRequest().body("新增失败");
        }
    }
}
